package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.org.AdmOrgUserSaveDTO;
import top.hcode.hoj.pojo.entity.org.OrgUser;
import top.hcode.hoj.pojo.form.AdmQueryOrgUserForm;
import top.hcode.hoj.pojo.vo.org.AdmOrgUserVO;
import top.hcode.hoj.service.UserAuthService;
import top.hcode.hoj.service.admin.AdminOrgUserService;

/**
 * @author orangej
 * @since 2025-01-21
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AdminOrgUserController {

    private final AdminOrgUserService orgUserService;
    private final UserAuthService userAuthService;

    @GetMapping("/admin/org-user/list")
    public CommonResult<IPage<AdmOrgUserVO>> getOrgUserList(@Validated AdmQueryOrgUserForm form) {
        return CommonResult.successResponse(orgUserService.getOrgUserList(form));
    }

    @PostMapping("/admin/org-user/save")
    public CommonResult<OrgUser> saveOrgUser(@RequestBody AdmOrgUserSaveDTO orgUser) {
        return CommonResult.successResponse(orgUserService.saveOrgUser(orgUser));
    }

    @PostMapping("/admin/org-user/delete")
    public CommonResult<Void> deleteOrgUser(@RequestBody BaseIdDTO dto) {
        orgUserService.deleteOrgUser(dto.getId());
        return CommonResult.successResponse();
    }

}
